package com.xxzb.pack0823.线程同步.互斥同步;

//火车票类
public class Ticket {
    private int number=10;
    private static final Object LOCK=new Object();

    //售票方法
    public void saleTicket(){
        synchronized (LOCK){
            if(number>0){
                System.out.println(Thread.currentThread().getName()+":销售第"+number+"张票");
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                number--;
            }else {
                System.out.println("票已售完......");
            }
        }
    }
}
